package palmtop.com.palmtop.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.beardedhen.androidbootstrap.AwesomeTextView;

import net.grandcentrix.tray.AppPreferences;

import java.util.ArrayList;

import palmtop.com.palmtop.R;
import palmtop.com.palmtop.activity.ClueWxdetailActivity;
import palmtop.com.palmtop.activity.CluedetailActivity;
import palmtop.com.palmtop.model.Clue;
import palmtop.com.palmtop.util.BadgeView;

/**
 * Created by Administrator on 2017/9/1.
 */

public class WxClueAdapter extends BaseAdapter {
    private ArrayList<Clue> arrlist;
    private Context context;
    String role_id;


    public WxClueAdapter(ArrayList<Clue> arrlist, Context context) {
        this.arrlist = arrlist;
        this.context = context;
        AppPreferences appPreferences = new AppPreferences(context);
        role_id = appPreferences.getString("role_id","");
    }

    @Override
    public int getCount() {
        return arrlist.size();
    }

    @Override
    public Object getItem(int i) {
        return arrlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int pos, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_cluewx,null);
        AwesomeTextView reportman = view.findViewById(R.id.reportman);
        AwesomeTextView cluetypename = view.findViewById(R.id.cluetypename);
        final AwesomeTextView taskname1 = view.findViewById(R.id.taskname1);
//        AwesomeTextView status = view.findViewById(R.id.status);

        Button xiangqing = view.findViewById(R.id.xiangqing);

        final Clue clue = arrlist.get(pos);
        if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
            if(!clue.getReadflag().equals("1")){
                BadgeView badge = new BadgeView(context,taskname1);
                badge.setText("未读");
                badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
                badge.show();
            }
        }

        reportman.setText(clue.getReportman());
        cluetypename.setText(clue.getAddtime());

        /*if(clue.getStatus().equals("1")){
            status.setText("民警已采纳");
        }else if(clue.getStatus().equals("2")){
            status.setText("民警未采纳");
        }else{
            status.setText("待确认");
        }*/
        xiangqing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("clue",clue);
                intent.setClass(context,ClueWxdetailActivity.class);
                context.startActivity(intent);

            }
        });

        return view;
    }
}
